<template>
  <div>

    <h3 align="center">招聘人员</h3>
    <el-button type="primary" @click="add">新增</el-button>
    <el-input placeholder="请输入内容" prefix-icon="el-icon-search" v-model="keyWord" style="width: 10%"></el-input>
    <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
    <el-table :data="applyList" style="width: 100%">

      <el-table-column label="招聘者编号">
        <!-- 插槽，和迭代变量一个意思-->
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyId }}</span>
        </template>
      </el-table-column>

      <el-table-column label="招聘者姓名">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyName }}</span>
        </template>
      </el-table-column>

      <el-table-column label="招聘者性别">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applySex }}</span>
        </template>
      </el-table-column>

      <el-table-column label="招聘者出生日期">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyBir }}</span>
        </template>
      </el-table-column>

      <el-table-column label="招聘者电话">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyPhone }}</span>
        </template>
      </el-table-column>

      <el-table-column label="招聘者学历">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyEducation }}</span>
        </template>
      </el-table-column>K

      <el-table-column label="招聘者邮箱地址">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyEmail }}</span>
        </template>
      </el-table-column>

      <el-table-column label="应聘岗位">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyJob }}</span>
        </template>
      </el-table-column>

      <el-table-column label="应聘时间">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyDate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="应聘状态">
        <template slot-scope="scope">

          <span style="margin-left: 10px">{{ scope.row.applyStatus }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="update(scope.row)">编辑</el-button><br>
          <el-button size="mini" type="danger" @click="delInfo(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <!-- page-size 默认每页显示条数-->
      <el-pagination @size-change="selectPage" @current-change="handleCurrentChange" :current-page="curPage"
        :page-sizes="[1, 3, 5, 10]" :page-size="rows" layout="jumper,total, sizes, prev, pager, next" :total="total">
      </el-pagination>

    </div>

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="isShow" width="30%">

      <el-form ref="form" label-width="80px">
        <br>
        <el-form-item label="姓名">
          <el-col :span="22">
            <input type="hidden" v-model="applyForm.applyId" />
            <el-input placeholder="请输入姓名" v-model="applyForm.applyName"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="请输入性别">
          <el-select v-model="applyForm.applySex" placeholder="请选择性别">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="请输入出生日期">
          <el-col :span="22">
            <el-date-picker type="date" placeholder="选择日期" v-model="applyForm.applyBir" value-format="yyyy-MM-dd"
              style="width: 40%;">
            </el-date-picker>
          </el-col>
        </el-form-item>

        <el-form-item label="招聘者电话">
          <el-col :span="22">
            <el-input placeholder="请输入电话" v-model="applyForm.applyPhone"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="请输入学历">
          <el-select v-model="applyForm.applyEducation" placeholder="学历">
            <el-option label="小学" value="小学"></el-option>
            <el-option label="初中" value="初中"></el-option>
            <el-option label="高中" value="高中"></el-option>
            <el-option label="专科" value="专科"></el-option>
            <el-option label="本科" value="本科"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="博士" value="博士"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="招聘者邮箱地址">
          <el-col :span="22">
            <el-input placeholder="请输入邮箱地址" v-model="applyForm.applyEmail"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="应聘岗位">
          <el-col :span="22">
            <el-input placeholder="请输入应聘岗位" v-model="applyForm.applyJob"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="请输入应聘日期">
          <el-col :span="22">
            <el-date-picker type="date" placeholder="选择日期" v-model="applyForm.applyDate" value-format="yyyy-MM-dd"
              style="width: 40%;">
            </el-date-picker>
          </el-col>
        </el-form-item>

        <el-form-item label="应聘状态">
          <el-select v-model="applyForm.applyStatus" placeholder="请选择应聘状态">
            <el-option label="未处理" value="未处理"></el-option>
            <el-option label="简历通过" value="简历通过"></el-option>
            <el-option label="笔试通过" value="笔试通过"></el-option>
            <el-option label="面试通过" value="面试通过"></el-option>
            <el-option label="入职" value="招聘通过"></el-option>
            <el-option label="人才库" value="人才库"></el-option>
          </el-select>
        </el-form-item>

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="saveInfo">保存</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
  export default {
    name: "applyList",
    data() {
      return {
        applyList: [],
        title: "新增", //模态框的标题
        keyWord: "",
        applyForm: { //表单请求对象
          applyId: null,
          applyName: "",
          applySex: "",
          applyBir: "",
          applyPhone: "",
          applyEducation: "",
          applyEmail: "",
          applyJob: "",
          applyDate: "",
          applyStatus: ""
        },
        total: 0, //总条数
        totalPage: 0, //总页数
        curPage: 1, //当前页
        rows: 5, //每页显示条数,
        isShow: false
      }
    },
    methods: {
      loaddata() { //加载数据
        var mythis = this;
        $.ajax({
          url: "http://localhost:8080/apply/list05",
          type: "get",
          data: {
            "page": mythis.curPage,
            "row": mythis.rows,
            "keyWord": mythis.keyWord,
          },
          dataType: "json",
          success: function(data) {
            console.log(data)
            mythis.applyList = data.info;
            mythis.total = data.total;
            mythis.totalPage = data.totalPage
          }
        })
      },
      add() { //打开新增模态框
        //显示模态框
        this.isShow = true;
        //更改模态框的标题
        this.title = "新增";
        //清除表单元素
        this.applyForm.applyId = null;
        this.applyForm.applyName = "";
        this.applyForm.applySex = "";
        this.applyForm.applyBir = "";
        this.applyForm.applyPhone = "";
        this.applyForm.applyEducation = "";
        this.applyForm.applyEmail = "";
        this.applyForm.applyJob = "";
        this.applyForm.applyDate = "";
        this.applyForm.applyStatus = "";
      },
      update(x) { //打开修改模态框
        //显示模态框
        this.isShow = true;
        //更改模态框的标题
        this.title = "修改";
        console.log(x)
        //把选中的值赋值给模态框的表单元素
        this.applyForm.applyId = x.applyId;
        this.applyForm.applyName = x.applyName;
        this.applyForm.applySex = x.applySex;
        this.applyForm.applyBir = x.applyBir;
        this.applyForm.applyPhone = x.applyPhone;
        this.applyForm.applyEducation = x.applyEducation;
        this.applyForm.applyEmail = x.applyEmail;
        this.applyForm.applyJob = x.applyJob;
        this.applyForm.applyDate = x.applyDate;
        this.applyForm.applyStatus = x.applyStatus;

      },
      saveInfo() { //保存
        var url = ""
        if (this.title == "修改") {
          url = "http://localhost:8080/apply/update"
        } else {
          url = "http://localhost:8080/apply/add"
        }

        var mythis = this;
        $.ajax({
          url: url,
          type: "get",
          data: mythis.applyForm,
          dataType: "json",
          success: function(data) {
            console.log(data)
            //alert(data.info);
            //mythis.$alert(data.info)
            mythis.$message(data.info)
            if (data.info == "保存成功") {
              //关闭模态框
              mythis.isShow = false;
              //刷新
              mythis.loaddata();
            }
          }
        })
      },
      delInfo(x) { //删除
        var mythis = this;
        this.$confirm("你确定要删除数据吗?").then(function() {
          $.ajax({
            url: "http://localhost:8080/apply/del",
            type: "get",
            data: {
              "id": x.applyId
            },
            dataType: "json",
            success: function(data) {
              mythis.$alert(data.info)
              if (data.info == "删除成功") {
                //刷新
                mythis.loaddata();
              }
            }
          })
        });

      },
      selectPage(v) { //用户选择页数
        this.rows = v;
        this.loaddata();
      },
      handleCurrentChange(v) { //当前页触发事件
        this.curPage = v;
        this.loaddata();
      },

      search() {
        var mythis = this;
        $.ajax({
          url: "http://localhost:8080/apply/list",
          type: "get",
          data: {
            "page": mythis.curPage,
            "row": mythis.rows,
            "keyWord": mythis.keyWord,
          },
          dataType: "json",
          success: function(data) {
            console.log(data)
            mythis.applyList = data.info;
            mythis.total = data.total;
            mythis.totalPage = data.totalPage
          }
        })
      }
    },
    mounted() {
      this.loaddata();
      console.log(this.$route.query.info)
    }

  }
</script>

<style>
</style>
